from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from thrift.transport import TSocket, TTransport

from com.lxk.spi.inface import PersonService
from com.lxk.spi.inface.ttypes import Person, sex

class PersonServiceHandler:
    def __init__(self):
        self.log = {}

    def savePerson(self, person):
        print("PersonName: " + person.personName)
        print("Age: " + str(person.age))
        print("PersonSex: " + str(person.personSex))

    def getPerson(self, personId):
        print("personId: " + personId)
        person = Person("personName", 27, sex.FEMALE)
        return person

if __name__=="__main__":
    handler = PersonServiceHandler()
    processor = PersonService.Processor(handler)
    transport = TSocket.TServerSocket("127.0.0.1",8099)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    server = TServer.TSimpleServer(processor,transport,tfactory,pfactory)
    print("Python Server start ...")
    server.serve()